import {
	fetchList,
	getRentContractPageList
} from "@/views/wy-lessor/rentalSociety/api/finance-collection-receivable";
import editActual from "../edit/edit-actual";
import editData from "../edit/edit-data";
import editReceivable from "../edit/edit-receivable";
import editCheck from "../edit/edit-check";
import editReceive from "../edit/edit-receive";
import leadData from "../edit/lead-data";
import showActual from "../edit/show-actual";
import editAccounts from "../edit/edit-accounts";
import contractView from "@/views/wy-lessor/rentalSociety/views/contract/view.vue";
export default {
	provide() {
		return {
			// 更新核算列表
			initList: this.getListData,
			// 更新合同列表
			updateList: this.getTabListData
		};
	},
	components: {
		editActual,
		editData,
		editReceivable,
		editCheck,
		editReceive,
		leadData,
		showActual,
		editAccounts,
		contractView
	},
	data() {
		return {
			selectOp: [
				{
					label: "核查状态",
					name: "status",
					option: [
						{ label: "所有", value: "" },
						{ label: "待接收", value: "10" },
						{ label: "待核算", value: "11" }
					]
				}
			],
			contract: {
				// 列表数据
				tableData: [],
				// 请求参数
				params: {
					current: 1,
					size: 10,
					propertyNames: "",
					checkStatue: ""
				},
				// 分页
				pager: {
					total: 0, // 总页数
					current: 1, // 当前页数
					size: 10 // 每页显示多少条
				},
				// 页面loading
				loading: false
			},
			// 核算列表请求参数
			account: {
				// 筛选列表
				filterList: [
					{
						label: "付款项目",
						inputType: "dict",
						dictName: "charge_project_type_lessor",
						name: "chargeProjectName"
					},
					{
						label: "费用周期",
						inputType: "daterange",
						name: ["costPeriodStart", "costPeriodEnd"]
					}
					// { label: '应付日期', inputType: 'date', name: 'payableDate' },
					// { label: '结算状态', inputType: 'dict', multiple: false, dictName: 'pay_status', name: 'payStatus' },
					// { label: '发送状态', inputType: 'dict', multiple: false, dictName: 'send_status', name: 'sendStatus' },
				],
				// 表格列表数据
				tableData: [],
				// 请求参数
				params: {
					current: 1,
					size: 10,
					propertyNames: ""
				},
				// 分页
				pager: {
					total: 0, // 总页数
					current: 1, // 当前页数
					size: 10 // 每页显示多少条
				},
				// 页面loading
				loading: true
			},
			NewIcon: require("@/assets/images/new.png")
		};
	},
	beforeMount() {
		this.getListData();
		this.getTabListData();
	},
	methods: {
		// 切换核算列表
		changeAccountList(lessorContractId) {
			this.contract.tableData = this.contract.tableData.map(item => ({
				...item,
				active: item.lessorContractId == lessorContractId
			}));
			this.getListData({ lessorContractId, current: 1 });
		},
		//  获取合同列表
		getTabListData(params = {}) {
			let req = { ...this.contract.params, ...params };
			getRentContractPageList(req)
				.then(res => {
					const { current, size, total, records } = res.data.data;
					this.contract.tableData = records.map((item, index) => ({
						...item,
						active: index === 0
					}));
					this.contract.params = req;
					this.contract.pager = { total, current, size };
					if (records.length)
						this.getListData({
							lessorContractId: records[0].lessorContractId
						});
					else {
						this.account.tableData = [];
						this.account.loading = false;
					}
				})
				.catch(() => {
					this.account.loading = false;
				})
				.finally(() => {
					this.contract.loading = false;
				});
		},
		//获取核算列表
		getListData(params = {}) {
			this.account.loading = true;
			let req = { ...this.account.params, ...params };
			fetchList(req)
				.then(res => {
					const { current, size, total, records } = res.data.data;
					this.account.tableData = records;
					this.account.params = req;
					this.account.pager = { total, current, size };
				})
				.finally(() => {
					this.account.loading = false;
				});
		}
	}
};
